<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="影视ID" prop="movieBasicsId">
        <el-input
          v-model="queryParams.movieBasicsId"
          placeholder="请输入影视ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年份" prop="year">
        <el-input
          v-model="queryParams.year"
          placeholder="请输入年份"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['movie:yearVisits:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yearVisitsList">
      <el-table-column label="ID" align="center" prop="id" width="80" />
      <el-table-column label="影视ID" align="center" prop="movieBasicsId" width="100" />
      <el-table-column label="年份" align="center" prop="year"  />
      <el-table-column label="访问量" align="center" prop="yearPv" >
        <template #default="scope">
          <span style="color: #E6A23C; font-weight: bold;">{{ scope.row.yearPv }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="MovieYearVisits">
import { listMovieYearVisits, exportMovieYearVisits } from "@/api/movie/yearVisits";
import { getCurrentInstance, ref, reactive, toRefs } from 'vue';

const { proxy } = getCurrentInstance();
const { parseTime } = proxy;

const yearVisitsList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    movieBasicsId: null,
    year: null
  }
});

const { queryParams } = toRefs(data);

/** 查询年访问统计列表 */
function getList() {
  loading.value = true;
  listMovieYearVisits(queryParams.value).then(response => {
    yearVisitsList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('/movie/yearVisits/export', {
    ...queryParams.value
  }, `年访问统计_${new Date().getTime()}.xlsx`);
}

getList();
</script>
